<server language="JavaScript">
// BEGININC
<!--#INCLUDE file="server.inc" -->
// ENDINC

var clearPasswords = false ;
var dataRequests = new Array();
var qStr = RMAGetPropertyValue( "headers.url" );
if ( qStr )
{
	qStr = qStr.slice( qStr.indexOf( '?' ) + 1 );
	//dbgAlert( qStr );

	var param, arrayName, serverProp ;
	var tmp = qStr.split( "&" );
	for ( var i = 0; i < tmp.length; i++ )
	{
		param = tmp[ i ].split( "=" );

		// param[ 0 ] is the name of the client-side array the user wants the 
		// param[ 1 ] is the name of the server property/list the client wants 
		// the registry values for (stuffed into the client side array)
		arrayName = unescape( param[ 0 ] );
		serverProp = unescape( param[ 1 ] );

		// look for special case requests first
		// is the calling page asking whether there are pending changes for this page (contextID)?
		if ( arrayName == "contextID" )
		{
			emitVarDecl( "pendingChanges", (RMAGetFirstProperty( "contextconfig." + serverProp + ".config" ) ? true : false), 1 );
		}
		else if ( arrayName == "timeoutParam" ) 
		{
			clearPasswords = true ;
		}
		else if ( arrayName == "AllPorts" )
		{
			emitPorts();
		}
		else
		{
			if ( arrayName && serverProp )
			{
				// the serverProp string may contain multiple, comma-seperated property names
				serverProp = serverProp.split( /\s*,\s*/ ); //serverProp is now an array of property names

				// data to be stored in, the user may pass multiple arrayname=serverprop pairs
				// where the arrayname is repeated

				if ( dataRequests[ arrayName ] == null )
					dataRequests[ arrayName ] = new Array();

				for ( var x = 0; x < serverProp.length; x++ )
				{
					if ( serverProp[ x ] )
						dataRequests[ arrayName ].push( serverProp[ x ] );
				}
			}
		}
	}
}

for ( var arrayName in dataRequests )
{
	//dbgAlert( arrayName );
	emitVarDecl( arrayName, "new Array()", 1 );

	//dbgAlert( dataRequests[ arrayName ] );
	for ( var i = 0; i < dataRequests[ arrayName ].length; i++ )
	{
		serverProp = dataRequests[ arrayName ][ i ];

		//assum "config." prefix
		//if serverProp does not begin with "config." AND is not one of the 
		//other common registry roots, then append "config." to the property Name
		if ( -1 == serverProp.leftProp().search( /config|server|headers|license|results|DistributedLicensing/ ) )
		{
			serverProp = "config." + serverProp ;
		}

		if ( RMAGetFirstProperty( serverProp ) || ( RMAGetPropertyValue( serverProp ) != null ) )
		{
			if ( ! RMAGetFirstProperty( serverProp ) )
			{
				emitArrayProp( arrayName, serverProp.rightProp( -1 ), RMAGetPropertyValue( serverProp ) );
			}
			else
			{
				emitPropsToJSArray( serverProp, arrayName, 0, 0, clearPasswords );
			}
		}
	}
}

function emitPorts ()
{
	// for reference, display all the other ports being used
	allPorts = new Array();

	var portNo ;
	function findPortsCallback( prop, val, curDepth )
	{
		// filter out ports that are used for allowances or that refer to ports
		// on other servers
		if ( prop.bSearch( /BroadcastDistribution\.Destinations|AccessControl|ProxyRoutingTable|WebServerPort|SplitterSourceList|LicensePublishers|Windows Media Live Broadcast Source/i ) )
			return ;

		portNo = parseInt( val );
		if ( (prop.rightProp().toLowerCase() != "transport") && 
			 (! isNaN( portNo )) && (portNo > 0) )
		{
			//trim off "config."
			allPorts[ prop.rightProp( -1 ) ] = val ;
		}
	}

	// enumerate through all the config. registry properties named *Port

	findSubProp( "config", ".*(Port|PortRange)", findPortsCallback );

	emitServArrayToClientArray( allPorts, "allPorts" );
}
</server>


